package ch.soreco.standard.xexpenses.utils;

//@author: trung do
import ch.ivyteam.ivy.addons.filemanager.ReturnedMessage;
import ch.ivyteam.ivy.addons.filemanager.html.thumbnailer.HtmlFileManagerThumbnailer;
import ch.ivyteam.ivy.environment.Ivy;

public class ThumbnailManager {;
	public static final String DEFAULT_THUMBNAIL_TYPE = ".jpg";
	private static HtmlFileManagerThumbnailer thumbnailMaker;

	/**
	 * create thumbnail and insert it to DB
	 * 
	 * @param javFile
	 * @return
	 * @throws Exception
	 */
	public static ReturnedMessage createThumbnail(java.io.File javFile) throws Exception {
		ReturnedMessage reMsg = new ReturnedMessage();
		thumbnailMaker = new HtmlFileManagerThumbnailer();
		Ivy.log().info("Start creating thumbnail");
		try {
			if(thumbnailMaker == null) {
				Ivy.log().info("thumbnailMaker == null");
				return reMsg;
			}
			reMsg = thumbnailMaker.createThumbnail(javFile);
			
		} catch (Exception e) {
			Ivy.log().info("Exception:" + e.getMessage(), e);
		}

		return reMsg;
	}
}
